let util = {
    getCurrDays(){
        let date = new Date()
        return date.getDate()
    },
    getDays(year,month){
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                return 31;
            case 4:
            case 6:
            case 9:
            case 11:
                return 30;
            case 2:
                if(year%400 === 0 || (year % 100 !==0 && year % 4 === 0)){
                    return 29;
                }
                return 28;
        }

    },
    //iphone的safari和电脑版浏览器返回false,其他的返回true
    isUsefulPhone(){
        var userAgent = !navigator || !navigator.userAgent || navigator.userAgent.toLocaleLowerCase()
        userAgent = userAgent || ""
        if(userAgent.indexOf("iphone")>-1 || (userAgent.indexOf("android")===-1 && userAgent.indexOf("iphone")===-1)){
            return false
        }
        return true
    },
    getImageUrl(file,callback){
        console.log("file.size = " + file.size);  //file.size 单位为byte
        var reader = new FileReader();
        //读取文件过程方法
        reader.onloadstart = function (e) {
            console.log("开始读取....");
        }
        reader.onprogress = function (e) {
            console.log("正在读取中....");
        }
        reader.onabort = function (e) {
            console.log("中断读取....");
        }
        reader.onerror = function (e) {
            console.log("读取异常....");
        }
        reader.onload = function (e) {
            console.log("成功读取....");
            if(callback){
                callback(e.target.result)
            }
        }
        reader.readAsDataURL(file)
    },
    floatAdd(a,b){
        if (!a || a==='') return b
        if (!b || b==='') return a
        var sa = a+"",sb = b+""
        var prea = sa.indexOf("."),preb = sb.indexOf(".")
        if(prea === -1 && preb === -1) return a+b
        var sufa = prea === -1? 0: sa.length - prea - 1, sufb = preb === -1? 0 : sb.length - preb - 1
        var sufm = Math.abs(sufa - sufb)
        var sa1 = parseInt(sa.replace('.','')),sb1 = parseInt(sb.replace('.',''))
        if(sufm){
            sufm = Math.pow(10,sufm)
            sufa>sufb?sb1 = sb1*sufm : sa1 = sa1*sufm
        }
        var r = sa1 + sb1
        if(sufa || sufb) r = r/Math.pow(10,Math.max(sufa,sufb))
        return r
    }
}
export default util